package com.sbeam.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

//自动赋值时配置
@Component  //将对象交给容器管理
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        Integer level = 0;
        Integer credits = 0;
        Integer points = 0;

        this.setFieldValByName("created",date,metaObject );
        this.setFieldValByName("level",level,metaObject );
        this.setFieldValByName("credits",credits,metaObject );
        this.setFieldValByName("points",points,metaObject );

        this.setFieldValByName("updated",date,metaObject );
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("updated",date,metaObject );
    }
}
